/**
 * 
 */
package com.siss.tenancy.exception;

import com.siss.tenancy.msg.RspMessage;
import com.siss.tenancy.vo.CodeDesc;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;


/**
 *  基类异常处理
 * @author ygw
 * @version 2017年6月7日 
 */
@SuppressWarnings("serial")
public abstract class BaseException extends RuntimeException {
	
	public BaseException() {
	}

	public BaseException(Throwable ex) {
		super(ex);
	}

	public BaseException(String message) {
		super(message);
	}

	public BaseException(String message, Throwable ex) {
		super(message, ex);
	}
	
	public void handler(RspMessage rsp, Map<String, CodeDesc> mapcode) {
		rsp.setCode(mapcode.get(getCodeDescFinal()).getCode());
		if (StringUtils.isNotBlank(getMessage())) {
			rsp.setMessage(getMessage());
		} 
		else {
			rsp.setMessage(mapcode.get(getCodeDescFinal()).getMessage());
		}
		
	}

	protected abstract  String getCodeDescFinal();
}
